#include "zf_common_headfile.h"
#include "flash.h"

/*-------------------------------------------------------------------------------------------------------------------
  @brief     写入flash
  @param     null
  @return    null
  Sample     Write_Flash();
  @note      将各项参数写入flash
-------------------------------------------------------------------------------------------------------------------*/
void  Write_Flash(void)
{
    flash_union_buffer[0].float_type = Set_Pid.S_kp;
    flash_union_buffer[1].float_type = Set_Pid.S_kd;
    flash_union_buffer[2].float_type = Set_Pid.C_kp;
    flash_union_buffer[3].float_type = Set_Pid.C_kd;
    flash_union_buffer[4].float_type = Set_Pid.Sp_kp;
    flash_union_buffer[5].float_type = Set_Pid.Sp_ki;

    flash_union_buffer[6].float_type = Set_Pid.Cc_kp;
    flash_union_buffer[7].float_type = Set_Pid.Cc_kd;

    flash_union_buffer[8].int16_type = Target_Speed.Down_Target_Speed;
    flash_union_buffer[9].int16_type = Target_Speed.Straight_Target_Speed;
    flash_write_page_from_buffer(FLASH_SECTION_INDEX, FLASH_PAGE_INDEX);        // 向指定 Flash 扇区的页码写入缓冲区数据
}

/*-------------------------------------------------------------------------------------------------------------------
  @brief     读取flash
  @param     null
  @return    null
  Sample     Read_Flash();
  @note      将各项参数从flash中读取
-------------------------------------------------------------------------------------------------------------------*/
void  Read_Flash(void)
{
    flash_read_page_to_buffer(FLASH_SECTION_INDEX, FLASH_PAGE_INDEX);           // 将数据从 flash 读取到缓冲区

    Set_Pid.S_kp = flash_union_buffer[0].float_type;
    Set_Pid.S_kd = flash_union_buffer[1].float_type;
    Set_Pid.C_kp = flash_union_buffer[2].float_type;
    Set_Pid.C_kd = flash_union_buffer[3].float_type;
    Set_Pid.Sp_kp = flash_union_buffer[4].float_type;
    Set_Pid.Sp_ki = flash_union_buffer[5].float_type;
    Set_Pid.Cc_kp = flash_union_buffer[6].float_type;
    Set_Pid.Cc_kd = flash_union_buffer[7].float_type;

    Target_Speed.Down_Target_Speed = flash_union_buffer[8].int16_type;
    Target_Speed.Straight_Target_Speed = flash_union_buffer[9].int16_type;


}

